import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';
import { ImagerasterService } from './imageraster.service';
import { ImagerasterController } from './imageraster.controller';
import { Imageraster } from './entities/imageraster.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { FileList } from '../file-list/entities/file-list.entity';
import * as path from 'path';
import { PublicResource } from 'src/public_resource/entities/public_resource.entity';
@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: function (req, fileName, callback) {
          try {
            callback(
              null,
              path.resolve(process.env.FILE_PATH + '/imageRaster'),
            );
          } catch (error) {
            console.error('Error in setting imageRaster destination:', error);
          }
        },
        filename: (_, file, callback) => {
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
    TypeOrmModule.forFeature([Imageraster]),
    TypeOrmModule.forFeature([FileList]),
    TypeOrmModule.forFeature([PublicResource])
  ],
  controllers: [ImagerasterController],
  providers: [ImagerasterService],
  exports: [ImagerasterService],
})
export class ImagerasterModule {}
